<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8" />
<title>广告位类型管理</title>
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/icon.css">
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.min.js"></script>
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$('#mytable').datagrid({
		nowrap: false,
		striped: true,
		url:'<{:U("AdplaceType/indexjson")}>',
		loadMsg:'数据正在加载，请稍候...',
		columns:[[
			{field:'table_id',checkbox:true},
			{field:'table_sort',title:'排序',width:50,align:"center"},
			{field:'table_name',title:'广告位类型名称',width:300,align:"left"},
			{field:'table_info',title:'描述',width:300,align:"left",formatter:function(value){
				if(value.length > 20){
					value = value.substring(0,20)+"...";
				}
				return value;
			}},
			{field:'table_status',title:'状态',width:50,align:"left",formatter:function(value){
				if(value=='1'){
					return '<font color=red>删除</font>';
				}else{
					return '正常';
				}
			}}
		]],
		singleSelect:true,
		fit:true,
		toolbar:[{
			text:'新增广告位类型',
			iconCls:'icon-add',
			handler:addAction
		},'-',{
			text:'编辑广告位类型',
			iconCls:'icon-edit',
			handler:editAction
		},'-',{
			text:'删除广告位类型',
			iconCls:'icon-remove',
			handler:removeAction
		}]
	});
});
function addAction(){
	$("#form_name").val('');
	$("#form_info").val('');
	$("#form_sort").val('0');
	$("#formWindow").window('setTitle','新增广告位类型');
	$("#submit").unbind("click");
	$("#submit").bind("click",{action:"<{:U('add')}>"},checkSubmit);
	$("#formWindow").window('open');
	$("#myLayout").layout('resize');
}
function editAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位类型再编辑！','error');
	}else{
		
		$("#form_name").val(selected.table_name);
		$("#form_info").val(selected.table_info);
		$("#form_sort").val(selected.table_sort);
		$("#formWindow").window('setTitle','编辑广告位类型');
		$("#submit").unbind("click");
		$("#submit").bind("click",{action:"<{:U('edit')}>", form_id: selected.table_id},checkSubmit);
		$("#formWindow").window('open');
		$("#myLayout").layout('resize');
	}
}
function removeAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位类型再删除！','error');
	}else{
		$.messager.confirm('提示消息','确认删除？',function(r){
			if(r){
				$.post('<{:U("remove")}>',{ form_id: selected.table_id},function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.info,'error');
					}else{
						$.messager.alert('提示消息',data.info,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function closeForm(){
	$("#formWindow").window('close');
}
function checkSubmit(event){
	if(!$("#myForm").form('validate')){
		$.messager.alert('错误消息','请确保表单信息无误再提交！','error');
	}else{
		closeForm();
		$.post(event.data.action,$('#myForm').serialize() +'&form_id='+event.data.form_id,function(data){
			if(data.status=='false'){
				$.messager.alert('错误消息',data.info,'error');
			}else{
				$.messager.alert('提示消息',data.info,'info',function(){
					$("#mytable").datagrid('reload');
				});
			}
		},"json"); 
	}
}
</script>
</head>
<body class="easyui-layout">
<div region="center" title="广告位设置-&gt;广告位类型管理">
<table id="mytable"></table>
</div>
<div id="formWindow" class="easyui-window" title="新增广告位类型" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:500px;height:300px;padding:5px;">
	<div class="easyui-layout" fit="true" id="myLayout">
		<div region="center" border="false" style="padding:5px;background:#fafafa;border:1px solid #ccc;">
		<form id="myForm" method="post">
			<table>
				<tr><td>广告位类型名称：</td><td><INPUT class="easyui-validatebox" required="true" missingMessage="广告位类型名称不能为空" TYPE="text" NAME="form_name" id="form_name" style="width:250px"></td></tr>
				<tr><td>描述：</td><td><TEXTAREA class="easyui-validatebox" NAME="form_info" id="form_info" style="width:250px;height:50px;"></TEXTAREA></td></tr>
				<tr><td>排序：</td><td><INPUT TYPE="text" NAME="form_sort" id="form_sort" style="width:50px"></td></tr>
			</table>
		</form>
		</div>
		<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
			<a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="submit">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="closeForm()">取消</a>
		</div>
	</div>
</div>
</body>
</html>